package com.huawei.appmarket.framework.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Path.Op;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import o.dky.c;
import o.dky.d;
import o.dky.o;
import o.Logger;

public class RoundCornerLayout extends RelativeLayout {
    private RectF ʻ;
    private int ʼ;
    private float[] ˊ;
    private Paint ˋ;
    public boolean ˎ;
    private Path ˏ;
    private int ॱ;

    public RoundCornerLayout(Context context) {
        this(context, null);
    }

    public RoundCornerLayout(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public RoundCornerLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊ = new float[8];
        ˏ(context, attributeSet);
    }

    private void ˏ(Context context, AttributeSet attributeSet) {
        if (attributeSet != null) {
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, o.ߴ);
            try {
                this.ʼ = obtainStyledAttributes.getDimensionPixelSize(o.ॱˍ, getResources().getDimensionPixelSize(c.ˏ));
                int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(o.ॱʾ, 0);
                this.ॱ = obtainStyledAttributes.getColor(o.ॱˌ, getResources().getColor(d.ˎ));
                int dimensionPixelSize2 = obtainStyledAttributes.getDimensionPixelSize(o.ॱˈ, dimensionPixelSize);
                int dimensionPixelSize3 = obtainStyledAttributes.getDimensionPixelSize(o.ߺ, dimensionPixelSize);
                int dimensionPixelSize4 = obtainStyledAttributes.getDimensionPixelSize(o.ߵ, dimensionPixelSize);
                dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(o.ॱʿ, dimensionPixelSize);
                this.ˎ = obtainStyledAttributes.getBoolean(o.ॱˑ, false);
                float[] fArr = this.ˊ;
                float f = (float) dimensionPixelSize2;
                this.ˊ[1] = f;
                fArr[0] = f;
                float[] fArr2 = this.ˊ;
                float f2 = (float) dimensionPixelSize3;
                this.ˊ[3] = f2;
                fArr2[2] = f2;
                fArr2 = this.ˊ;
                float f3 = (float) dimensionPixelSize;
                this.ˊ[5] = f3;
                fArr2[4] = f3;
                float[] fArr3 = this.ˊ;
                float f4 = (float) dimensionPixelSize4;
                this.ˊ[7] = f4;
                fArr3[6] = f4;
                if (obtainStyledAttributes != null) {
                    obtainStyledAttributes.recycle();
                }
            } catch (RuntimeException e) {
                Logger.e("RoundCornerLayout", "RoundCornerLayout initAttrs() " + e.getMessage());
                if (obtainStyledAttributes != null) {
                    obtainStyledAttributes.recycle();
                }
            } catch (Throwable th) {
                if (obtainStyledAttributes != null) {
                    obtainStyledAttributes.recycle();
                }
            }
        }
        this.ˏ = new Path();
        this.ˋ = new Paint();
        this.ˋ.setColor(-1);
        this.ˋ.setAntiAlias(true);
        this.ʻ = new RectF();
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        this.ʻ.set(0.0f, 0.0f, (float) i, (float) i2);
        RectF rectF = new RectF();
        rectF.left = (float) getPaddingLeft();
        rectF.top = (float) getPaddingTop();
        rectF.right = (float) (i - getPaddingRight());
        rectF.bottom = (float) (i2 - getPaddingBottom());
        this.ˏ.reset();
        this.ˏ.addRoundRect(rectF, this.ˊ, Direction.CW);
    }

    public void draw(Canvas canvas) {
        if (this.ˎ) {
            canvas.save();
            canvas.clipPath(this.ˏ);
            super.draw(canvas);
            canvas.restore();
            return;
        }
        super.draw(canvas);
    }

    protected void dispatchDraw(Canvas canvas) {
        canvas.saveLayer(this.ʻ, null, 31);
        super.dispatchDraw(canvas);
        if (this.ʼ > 0) {
            this.ˋ.setXfermode(new PorterDuffXfermode(Mode.SRC_OVER));
            this.ˋ.setStrokeWidth((float) this.ʼ);
            this.ˋ.setColor(this.ॱ);
            this.ˋ.setStyle(Style.STROKE);
            canvas.drawPath(this.ˏ, this.ˋ);
        }
        this.ˋ.setColor(-1);
        this.ˋ.setStyle(Style.FILL);
        if (VERSION.SDK_INT <= 27) {
            this.ˋ.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
            canvas.drawPath(this.ˏ, this.ˋ);
        } else {
            this.ˋ.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));
            Path path = new Path();
            path.addRect(0.0f, 0.0f, (float) ((int) this.ʻ.width()), (float) ((int) this.ʻ.height()), Direction.CW);
            path.op(this.ˏ, Op.DIFFERENCE);
            canvas.drawPath(path, this.ˋ);
        }
        canvas.restore();
    }

    public void setRadius(int i) {
        for (int i2 = 0; i2 < this.ˊ.length; i2++) {
            this.ˊ[i2] = (float) i;
        }
        invalidate();
    }
}
